<?php

namespace addons\Asset\services;

use common\enums\StatusEnum;
use common\components\Service;
use addons\Asset\common\models\Asset;

/**
 * Class MemberService
 * @package addons\TinyShop\services\member
 * @author YiiFrame <21931118@qq.com>
 */
class AssetService extends Service
{
    public function getSum($cate_id = '')
    {
        return Asset::find()
            ->select([
                'sum(purchase_price*num) as purchase_price',
            ])
            ->where(['>', 'status', StatusEnum::DISABLED])
            ->andFilterWhere(['cate_id' => $cate_id])
            ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
            ->asArray()
            ->one();
    }

    public function getName($id)
    {
        return Asset::findOne($id)->title;
    }

    public function getAsset($id)
    {
        return Asset::findOne($id);
    }
}